/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Block;

import DAO.AccountDAO;
import DAO.ConnectDatabase;
import DAO.DepartmentDAO;
import Helper.AccountHelper;
import Helper.DepartmentHelper;
import common.Constant;
import java.sql.ResultSet;
import javax.swing.DefaultComboBoxModel;

/**
 *
 * @author KIENLT
 */
public class Scheduler extends javax.swing.JPanel {
    ResultSet rs = null;
    String accLevel;
    /**
     * Creates new form Scheduler
     */
    public Scheduler(String accLevel) {
        initComponents();
        changeLanguage();
        this.accLevel = accLevel;
        loadComboboxDepartment();
        loadComboboxAccount();
    }
    
    private void loadComboboxDepartment(){
        try {
            DefaultComboBoxModel cbxDepart = new DefaultComboBoxModel();
            rs = DepartmentDAO.FillAll(ConnectDatabase.ConnectionDatabase());
            while(rs.next()){
                String strId = rs.getString("DepartmentId");
                String strName = rs.getString("DepartmentName");
                cbxDepart.addElement(new DepartmentHelper(strId, strName));
            }
            cbxDepartment.setModel(cbxDepart);
        } catch (Exception ex) {
            try {
                ConnectDatabase.CloseDB(rs);
                ConnectDatabase.CloseDB(ConnectDatabase.ConnectionDatabase());
            } catch (Exception ex1) {
                ex1.printStackTrace();
            }
            ex.printStackTrace();
        }
    }
    
    private void loadComboboxAccount(){
        try {
            DefaultComboBoxModel cbxDName = new DefaultComboBoxModel();
            AccountHelper acc = new AccountHelper();
            String departmentId = ((DepartmentHelper)(cbxDepartment.getSelectedItem())).getDepartmentID();
            acc.setAccountLevelId(accLevel);
            acc.setDepartmentId(departmentId);
            rs = AccountDAO.FillAll(ConnectDatabase.ConnectionDatabase(), acc);
            while(rs.next()){
                String strId = rs.getString("AccountId");
                String strName = rs.getString("FullName");
                cbxDName.addElement(new AccountHelper(strId, strName));
            }
            cbxDortorName.setModel(cbxDName);
        } catch (Exception ex) {
            try {
                ConnectDatabase.CloseDB(rs);
                ConnectDatabase.CloseDB(ConnectDatabase.ConnectionDatabase());
            } catch (Exception ex1) {
                ex1.printStackTrace();
            }
            ex.printStackTrace();
        }
    }

    private void changeLanguage() {
        if(Constant.getLanguage() == 0){
            Constant.initBundle();
            getLanguage();
        }else{
            Constant.initBundle();
            getLanguage();
        }
    }
    
    private void getLanguage() {
        lblSchedulerID.setText(Constant.getBundle().getString("schedulerID"));
        lblScheduler.setText(Constant.getBundle().getString("schedulerDate"));
        lblDoctorName.setText(Constant.getBundle().getString("department"));
        btnAccept.setText(Constant.getBundle().getString("accept"));
        btnUpdate.setText(Constant.getBundle().getString("update"));
        btnDelete.setText(Constant.getBundle().getString("delete"));
        btnAdd.setText(Constant.getBundle().getString("add"));
        btnSearch.setText(Constant.getBundle().getString("search"));
        lblWeek.setText(Constant.getBundle().getString("weekId"));
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnScheduler = new javax.swing.JPanel();
        lblScheduler = new javax.swing.JLabel();
        btnAccept = new javax.swing.JButton();
        btnAdd = new javax.swing.JButton();
        btnUpdate = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();
        btnSearch = new javax.swing.JButton();
        lblSchedulerID = new javax.swing.JLabel();
        txtSchedulerID = new javax.swing.JTextField();
        cbxDortorName = new javax.swing.JComboBox();
        lblDoctorName = new javax.swing.JLabel();
        cbxSheduler = new javax.swing.JComboBox();
        lblDepartment = new javax.swing.JLabel();
        cbxDepartment = new javax.swing.JComboBox();
        lblWeek = new javax.swing.JLabel();
        cbxSheduler1 = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setPreferredSize(new java.awt.Dimension(860, 560));

        pnScheduler.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        lblScheduler.setText("Scheduler");

        btnAccept.setText("Accept");

        btnAdd.setText("Add");

        btnUpdate.setText("Update");

        btnDelete.setText("Delete");

        btnSearch.setText("Search");

        lblSchedulerID.setText("SchedulerID");

        lblDoctorName.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lblDoctorName.setText("Doctor Name");

        lblDepartment.setText("Department");

        cbxDepartment.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbxDepartmentActionPerformed(evt);
            }
        });

        lblWeek.setText("Week");

        javax.swing.GroupLayout pnSchedulerLayout = new javax.swing.GroupLayout(pnScheduler);
        pnScheduler.setLayout(pnSchedulerLayout);
        pnSchedulerLayout.setHorizontalGroup(
            pnSchedulerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnSchedulerLayout.createSequentialGroup()
                .addContainerGap(24, Short.MAX_VALUE)
                .addGroup(pnSchedulerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnSchedulerLayout.createSequentialGroup()
                        .addGap(150, 150, 150)
                        .addComponent(btnAccept)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnAdd)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnUpdate)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnDelete)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSearch))
                    .addGroup(pnSchedulerLayout.createSequentialGroup()
                        .addGroup(pnSchedulerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(pnSchedulerLayout.createSequentialGroup()
                                .addComponent(lblSchedulerID, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtSchedulerID, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnSchedulerLayout.createSequentialGroup()
                                .addComponent(lblWeek, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cbxSheduler1, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(pnSchedulerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblDepartment)
                            .addComponent(lblScheduler))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnSchedulerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(cbxDepartment, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cbxSheduler, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(lblDoctorName, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cbxDortorName, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        pnSchedulerLayout.setVerticalGroup(
            pnSchedulerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnSchedulerLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(pnSchedulerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblSchedulerID)
                    .addComponent(txtSchedulerID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDepartment)
                    .addComponent(cbxDepartment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbxDortorName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDoctorName))
                .addGap(24, 24, 24)
                .addGroup(pnSchedulerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnSchedulerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblWeek)
                        .addComponent(cbxSheduler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnSchedulerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblScheduler)
                        .addComponent(cbxSheduler, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(pnSchedulerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAccept)
                    .addComponent(btnAdd)
                    .addComponent(btnUpdate)
                    .addComponent(btnDelete)
                    .addComponent(btnSearch))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 646, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pnScheduler, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnScheduler, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cbxDepartmentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbxDepartmentActionPerformed
        // TODO add your handling code here:
        loadComboboxAccount();
    }//GEN-LAST:event_cbxDepartmentActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAccept;
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnSearch;
    private javax.swing.JButton btnUpdate;
    private javax.swing.JComboBox cbxDepartment;
    private javax.swing.JComboBox cbxDortorName;
    private javax.swing.JComboBox cbxSheduler;
    private javax.swing.JComboBox cbxSheduler1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel lblDepartment;
    private javax.swing.JLabel lblDoctorName;
    private javax.swing.JLabel lblScheduler;
    private javax.swing.JLabel lblSchedulerID;
    private javax.swing.JLabel lblWeek;
    private javax.swing.JPanel pnScheduler;
    private javax.swing.JTextField txtSchedulerID;
    // End of variables declaration//GEN-END:variables
}
